//
//  main.cpp
//  
//
//  Created by Kun Zhao on 12/11/07.
//  Copyright (c) 2012 Kyoto University. All rights reserved.
//

#include <iostream>
#include <kvs/StructuredVolumeObject>
#include <kvs/StructuredVolumeImporter>
#include <kvs/UnstructuredVolumeObject>
#include "CubeToTetrahedra.h"
#include "WriteUnstructuredVolume.h"

int main( int agrc, char** argv )
{
    kvs::StructuredVolumeObject* object= new kvs::StructuredVolumeImporter( argv[1] );
    float min = object->minValue();
    float max = object->maxValue() / 8.0;
    std::cout << "min value: " << min << std::endl;
    std::cout << "max value: " << max << std::endl;
    float* pvalues = (float*)object->values().pointer();
    for ( size_t i = 0; i < object->nnodes(); i++) {
        if( pvalues[i] < min ) pvalues[i] = min;
        if( pvalues[i] > max ) pvalues[i] = max;
    }
    object->updateMinMaxValues();
    kvs::UnstructuredVolumeObject* volume = kvs::CubeToTetrahedra::Convert( *object );
    WriteUnstructuredVolume( volume, argv[2] );
}